package com.kitty.web.controller;

import com.kitty.web.controller.BaseController;
import com.kitty.web.common.AjaxResult;
import com.kitty.web.core.page.TableDataInfo;
import com.kitty.web.domain.PNewPetset;
import com.kitty.web.system.petset.service.IPNewPetsetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 宠物配置Controller
 * 
 * @author soul
 * @date 2022-06-23
 */
@Controller
@RequestMapping("/system/petset")
public class PNewPetsetController extends BaseController
{
    private String prefix = "system/petset";

    @Autowired
    private IPNewPetsetService pNewPetsetService;


    @GetMapping()
    public String petset()
    {
        return prefix + "/petset";
    }

    /**
     * 查询宠物配置列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PNewPetset pNewPetset)
    {
        startPage();
        List<PNewPetset> list = pNewPetsetService.selectPNewPetsetList(pNewPetset);
        return getDataTable(list);
    }



    /**
     * 新增宠物配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存宠物配置
     */

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PNewPetset pNewPetset)
    {
        return toAjax(pNewPetsetService.insertPNewPetset(pNewPetset));
    }

    /**
     * 修改宠物配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PNewPetset pNewPetset = pNewPetsetService.selectPNewPetsetById(id);
        mmap.put("pNewPetset", pNewPetset);
        return prefix + "/edit";
    }

    /**
     * 修改保存宠物配置
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PNewPetset pNewPetset)
    {
        return toAjax(pNewPetsetService.updatePNewPetset(pNewPetset));
    }

    /**
     * 删除宠物配置
     */

    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pNewPetsetService.deletePNewPetsetByIds(ids));
    }
}
